namespace MsForgeReboot.Services.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class FixRequiredFieldsInTheModel : DbMigration
    {
        public override void Up() {
            DropIndex("dbo.Users", "IX_Username");
            //DropIndex("dbo.Roles", "IX_Name");
            DropForeignKey("dbo.Comments", "BlogPostId", "dbo.BlogPosts");
            DropIndex("dbo.Comments", new[] { "BlogPostId" });
            AddColumn("dbo.Comments", "BlogPost_Id", c => c.Int());
            AlterColumn("dbo.Comments", "Body", c => c.String(nullable: false));
            AlterColumn("dbo.Comments", "CommentBy", c => c.String(nullable: false, maxLength: 150));
            AlterColumn("dbo.Tags", "Name", c => c.String(nullable: false, maxLength: 50));
            AlterColumn("dbo.Users", "Password", c => c.String(nullable: false, maxLength: 100));
            AlterColumn("dbo.Users", "Username", c => c.String(nullable: false, maxLength: 100));
            //AlterColumn("dbo.Roles", "Name", c => c.String(nullable: false, maxLength: 100));
            AlterColumn("dbo.Feeds", "URL", c => c.String(nullable: false, maxLength: 500));
            AddForeignKey("dbo.Comments", "BlogPost_Id", "dbo.BlogPosts", "Id");
            CreateIndex("dbo.Comments", "BlogPost_Id");
            CreateIndex("dbo.Users", "Username", true);
            //CreateIndex("dbo.Roles", "Name", true);
            DropColumn("dbo.Comments", "BlogPostId");
        }
        
        public override void Down()
        {
            DropIndex("dbo.Users", "IX_Username");
            //DropIndex("dbo.Roles", "IX_Name");
            AddColumn("dbo.Comments", "BlogPostId", c => c.Int(nullable: false));
            DropIndex("dbo.Comments", new[] { "BlogPost_Id" });
            DropForeignKey("dbo.Comments", "BlogPost_Id", "dbo.BlogPosts");
            AlterColumn("dbo.Feeds", "URL", c => c.String(maxLength: 500));
            //AlterColumn("dbo.Roles", "Name", c => c.String(maxLength: 100));
            AlterColumn("dbo.Users", "Username", c => c.String(maxLength: 100));
            AlterColumn("dbo.Users", "Password", c => c.String(maxLength: 100));
            AlterColumn("dbo.Tags", "Name", c => c.String(maxLength: 50));
            AlterColumn("dbo.Comments", "CommentBy", c => c.String(maxLength: 150));
            AlterColumn("dbo.Comments", "Body", c => c.String());
            DropColumn("dbo.Comments", "BlogPost_Id");
            CreateIndex("dbo.Comments", "BlogPostId");
            CreateIndex("dbo.Users", "Username", true);
            //CreateIndex("dbo.Roles", "Name", true);
            AddForeignKey("dbo.Comments", "BlogPostId", "dbo.BlogPosts", "Id", cascadeDelete: true);
        }
    }
}
